<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>十秒免单效果</title>
</head>

<body>
    <div>
        <div id="box">
            <div id="dian">.</div>
            <div id="block">00</div>
        </div>
        <button id="btn">长按免单</button>
    </div>
    <script>
        var btn = document.getElementById('btn');
        var block = document.getElementById('block');
        var t = 0;
        var timer;
        var time = function () {
            t++;
            if (t > 1200) {
                clearInterval(timer)
            } else {
                block.innerHTML = t;
            }
        }
        btn.onmousedown = function () {
            timer = setInterval(time, 10)
        }
        btn.onmouseup = function () {
            clearInterval(timer)
        }
    </script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 300px;
            height: 100px;
            background-color: aquamarine;
            margin: 100px auto;
            text-align: center;
            line-height: 100px;
            font-size: 30px;
            position: relative;
        }

        #dian {
            width: 100%;
            height: 100%;
            text-align: center;
        }

        #block {
            width: 100%;
            height: 100%;
            text-align: right;
            position: absolute;
            top: 0;
            left: -75px;
            letter-spacing: 15px;
        }

        #btn {
            width: 200px;
            height: 80px;
            border: 0;
            background-color: rgb(136, 136, 219);
            margin: 0 auto;
            display: block;
            font-size: 30px;
        }
    </style>
</body>

</html>